﻿package com.shichuan.components 
{
	import flash.external.ExternalInterface;
	import flash.text.TextFieldAutoSize;
	import flash.display.DisplayObject;
	import flash.text.TextField;
	
	/**
	 * ...
	 * @author Shi Chuan
	 */
	public class Cookie 
	{
		private var _cookieName:String;
		private var _cookieValue:String;
		private var _cookieExpiryDate:String;
		private var _cookieDomain:String;
		private var _cookiePath:String;
		private var _textField:TextField;
		
		public function Cookie() 
		{
			
			
		}
		
		
		public function getCookie(cookieName:String,textField:TextField)
		{  
			_cookieName = cookieName;
			_textField = textField;
			ExternalInterface.addCallback("sendCookieToFlash", sendCookieToFlash);
			ExternalInterface.call("getCookieNameFromFlash", _cookieName);	
		}
		
		public function setCookie(cookieName:String, value:String, expiryDate:String, domain:String, path:String):void 
		{  
			_cookieName = cookieName;
			_cookieValue = value;
			_cookieExpiryDate = expiryDate;
			//_cookieDomain = domain;
			//_cookiePath = path;
			ExternalInterface.call("setCookieFromFlash", _cookieName, _cookieValue, _cookieExpiryDate); 
		}
		
		public function clearCookie(cookieName:String) :void 
		{
			ExternalInterface.call("eraseCookie", _cookieName);
			
		}
		
		function sendCookieToFlash(str:String):void 
		{  
			(_textField as TextField).text = "From JavaScript:" + str; 
		}

		
	}
	
}